package logic

import (
	"context"
	"errors"
	"month/videosvr/internal/service"

	"month/videosvr/internal/svc"
	"month/videosvr/video"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateIkIndexLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateIkIndexLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateIkIndexLogic {
	return &CreateIkIndexLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// CreateIkIndex todo 创建ik分词器索引
func (l *CreateIkIndexLogic) CreateIkIndex(in *video.CreateIkIndexReq) (*video.CreateIkIndexRes, error) {
	// todo: add your logic here and delete this line
	is, err := service.EsIsIndex(in.Index)
	if err != nil {
		return &video.CreateIkIndexRes{}, err
	}
	if is.(bool) {
		return &video.CreateIkIndexRes{}, errors.New("索引已经存在")
	}
	_, err = service.CreateIkIndex(in.Index)
	if err != nil {
		return &video.CreateIkIndexRes{}, err
	}
	return &video.CreateIkIndexRes{}, nil
}
